package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.vo.IotProductVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2025/5/25 14:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/nursing/device")
public class DeviceController extends BaseController {


    private IDeviceService deviceService;

    @Autowired
    public void setDeviceService(IDeviceService deviceService){
        this.deviceService = deviceService;
    }


    @GetMapping("/queryProduct/{productKey}")
    @ApiOperation(value = "查询产品详情")
    public AjaxResult queryProduct(@PathVariable String productKey){
        return deviceService.queryProduct(productKey);
    }

    /**
     * 查询设备上报数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询设备上报数据")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId) {
        return AjaxResult.success(deviceService.queryServiceProperties(iotId));
    }


    /**
     * 获取设备详细信息
     */
    @GetMapping("/{iotId}")
    @ApiOperation("获取设备详细信息")
    public AjaxResult getInfo(@PathVariable("iotId") String iotId) {
        return success(deviceService.queryDeviceDetail(iotId));
    }

    @PostMapping("/syncProductList")
    public R syncProductList(){
        deviceService.syncProductList();
        return R.ok();
    }

    @GetMapping("/allProduct")
    public R<List<IotProductVo>> allProduct(){
        return R.ok(deviceService.allProduct());
    }

    /**
     * 查询设备维护列表
     */
    @ApiOperation("查询设备维护列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    @PostMapping("/register")
    @ApiOperation(value = "注册设备")
    public AjaxResult registerDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return success();
    }
}